package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/10 19:13
 * @description
 */
public class Code102 {
    List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> levelOrder(TreeNode root) {
        setList(root, 0);
        return result;
    }

    private void setList(TreeNode node, int level) {
        if (node != null) {
            if (level >= result.size()) {
                result.add(new ArrayList<>());
            }
            result.get(level).add(node.val);
            level++;
            setList(node.left, level);
            setList(node.right, level);
        }
    }
}
